package com.principle.factory.absfactory.pizzastore.order;

import com.principle.factory.absfactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class OrderPizza {
    AbsFactory absFactory;
    public OrderPizza(AbsFactory absFactory){
        setFactory(absFactory);
    }
    private void setFactory(AbsFactory absFactory){
        Pizza pizza=null;
        String orderType="";//用户输入
        this.absFactory=absFactory;
        do {
            orderType=gettype();
            //factory 可能是北京的工厂子类 也可能是伦敦的工厂子类
            pizza=absFactory.creatPizza(orderType);
            if (pizza!=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("失败");
                break;
            }
        }while (true);
    }
    private String gettype(){
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type");
            String line = reader.readLine();
            return line;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
